package com.efeichong.oss;

import com.efeichong.exception.BaseException;

import java.util.function.Consumer;

/**
 * @author lxk
 * @date 2020/11/5
 * @description 将异常类型转换为BaseException
 */
@FunctionalInterface
interface FunctionWithException<T, E extends Exception> {

    static <T, E extends Exception> Consumer<T> wrapper(FunctionWithException<T, E> fe) {
        return arg -> {
            try {
                fe.accept(arg);
            } catch (Exception e) {
                throw new BaseException(e);
            }
        };
    }

    void accept(T t) throws E;
}
